﻿@model ECMS.AppService.Model.Models.UserModel
@{
    Layout = null;
}
<div class="layui-body-header">
    <ul class="kit-breadcrumb">
        <li class="kit-item">
            <a href="#/">
                <i class="layui-icon">&#xe68e;</i>
                <span>首页</span>
            </a>
        </li>
        <li class="kit-separator">
            <i class="layui-icon">&#xe602;</i>
        </li>
        <li class="kit-item">
            <a href="#/user/list">
                <i class="layui-icon">&#xe658;</i>
                <span>用户管理</span>
            </a>
        </li>
        <li class="kit-separator">
            <i class="layui-icon">&#xe602;</i>
        </li>
        <li class="kit-item">
            <a>
                <span>新增用户</span>
            </a>
        </li>
    </ul>
</div>
<div class="layui-fluid">
    <div class="layui-row">
        <div class="layui-col-xs12">
            <div class="layui-card">
                <div class="layui-card-header">
                    <a href="javascript:history.back(-1);" title="返回"><i class="layui-icon">&#xe65c;</i></a>
                    @{
                        var showName = Model.Id == 0 ? "新增" : "编辑";
                    }
                    <span>@showName</span>
                </div>
                <div class="layui-card-body">
                    <form class="layui-form" action="">
                        <input type="hidden" name="id" value="@Model.Id" />
                        <input type="hidden" name="guid" value="@Model.Guid" />
                        @Html.AntiForgeryToken()
                        <div class="layui-form-item">
                            <label class="layui-form-label">登录名</label>
                            <div class="layui-input-block">
                                <input type="text" name="loginName" required lay-verify="required" value="@Model.LoginName" placeholder="请输入登录名" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">密码</label>
                            <div class="layui-input-inline">
                                <input type="password" name="password" required lay-verify="required" value="@Model.Password" placeholder="请输入密码" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">用户登录密码.</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">真实姓名</label>
                            <div class="layui-input-block">
                                <input type="text" name="realName" required lay-verify="required" value="@Model.RealName" placeholder="请输入真实姓名" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">手机号</label>
                            <div class="layui-input-block">
                                <input type="text" name="mobile" required lay-verify="required" value="@Model.Mobile" placeholder="请输入手机号" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">座机号</label>
                            <div class="layui-input-block">
                                <input type="text" name="tel" value="@Model.Tel" placeholder="请输入座机号" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">电子邮箱</label>
                            <div class="layui-input-block">
                                <input type="email" name="email" value="@Model.Email" placeholder="请输入电子邮箱" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">IP限制</label>
                            <div class="layui-input-inline">
                                @{
                                    var ipLimitEnabled = Model.IPLimitEnabled ? "checked" : "";
                                }
                                <input type="checkbox" name="IPLimitEnabled" value="true" @ipLimitEnabled lay-text="开启|关闭" lay-skin="switch">
                            </div>
                            <div class="layui-form-mid layui-word-aux">是否启用IP限制</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">允许IP</label>
                            <div class="layui-input-block">
                                <input type="text" name="allowIPAddresses" value="@Model.AllowIPAddresses" placeholder="允许登录的IP地址,多个以逗号隔开" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">锁定帐号</label>
                            <div class="layui-input-inline">
                                @{
                                    var lockoutEnabled = Model.LockoutEnabled ? "checked" : "";
                                }
                                <input type="checkbox" name="lockoutEnabled" value="true" lay-text="锁定|解锁" @lockoutEnabled lay-skin="switch">
                            </div>
                            <div class="layui-form-mid layui-word-aux">是否锁定帐号</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">解锁时间</label>
                            <div class="layui-input-inline">
                                <input type="text" name="lockoutEnd" id="lockoutEnd_hash" value="@Model.LockoutEnd.ToString("yyyy-MM-dd HH:mm:ss")" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">帐号解锁时间</div>
                        </div>
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">备注</label>
                            <div class="layui-input-block">
                                <textarea name="remark" placeholder="请输入内容" class="layui-textarea">@Model.Remark</textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 脚本 -->
<script>
    layui.use(['form', 'axios', 'laydate'], function () {
        var form = layui.form,
            axios = layui.axios,
            layer = layui.layer,
            laydate = layui.laydate;
        form.render();

        // 渲染时间
        laydate.render({
            elem: '#lockoutEnd_hash'
            , type: 'datetime'
        });

        //监听提交
        form.on('submit(formDemo)', function (data) {
            var layIndex = layer.load(2, {
                shade: [0.2, '#393D49']
            });
            console.log(data);
            axios.post('/User/Save', data.field)
                .then(function (response) {
                    if (response.status === 500) {
                        console.log(response);
                        throw new Error(response.statusText);
                    }
                    return response.data;
                })
                .then(function (res) {
                    layer.msg(res.message);
                    layer.close(layIndex);
                    if (res.success) {
                        location.href = "#/user/list";
                    }
                })
                .catch(function (err) {
                    console.log(err);
                    layer.close(layIndex);
                });

            return false;
        });
    });
</script>
<!-- 样式 -->
<style scoped>
</style>
